package com.yuan.config;

import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 初始化topic的配置
 *
 * @Author yuan
 * @Date 2021/9/26 13:47
 */
@Configuration
public class KafkaInitialConfig {


    /**
     * 创建一个名为testTopic的Topic并设置分区数partitions为8，
     * 分区副本replication-factor为2
     * @return
     */
    @Bean
    public NewTopic initialTopic() {
        System.out.println("begin to init initialTopic........................");
        return new NewTopic("yuantopic", 8, (short) 2);
    }

    /**
     * 如果要修改分区数，只需修改配置值重启项目即可
     * 修改分区数并不会导致数据的丢失，但是分区数只能增大不能减小
     * @return
     */
    @Bean
    public NewTopic updateTopic() {
        System.out.println("begin to init updateTopic........................");
        return new NewTopic("yuantopic",10, (short) 2 );
    }
}
